#ifndef __INCLUDED_CBL_AUTOBUFFER_H__
#error "CBL_AutoBuffer.hpp must not be used directly. Use CBL_AutoBuffer.h instead."
#else
#ifndef __INCLUDED_CBL_AUTOBUFFER_HPP__
#define __INCLUDED_CBL_AUTOBUFFER_HPP__

template <typename TType>
CAutoBuffer<TType>::CAutoBuffer()
	: m_pBuffer(NULL)
    , m_Size(0)
{
}

// -------------------------------------------------------------------------------------------------

template <typename TType>
CAutoBuffer<TType>::CAutoBuffer(const CAutoBuffer<TType>& _rCopy)
	: m_pBuffer(_rCopy.m_pBuffer)
    , m_Size(_rCopy.m_Size)
{
	CAutoBuffer& rCopy = const_cast<CAutoBuffer&>(_rCopy);
    rCopy.m_pBuffer = NULL;
    rCopy.m_Size = 0;
}

// -------------------------------------------------------------------------------------------------

template <typename TType>
CAutoBuffer<TType>::CAutoBuffer(TType*& _rpBuffer, uint32 _Size)
	: m_pBuffer(_rpBuffer)
	, m_Size(_Size)
{
	_rpBuffer = NULL;
}

// -------------------------------------------------------------------------------------------------

template <typename TType>
CAutoBuffer<TType>::~CAutoBuffer()
{
    delete[] m_pBuffer;
}

// -------------------------------------------------------------------------------------------------

template <typename TType>
CB_FORCEINLINE CAutoBuffer<TType>& CB_INLINE_ATTR CAutoBuffer<TType>::operator = (const CAutoBuffer<TType>& _rCopy)
{
    CAutoBuffer& rCopy = const_cast<CAutoBuffer&>(_rCopy);
    
    m_pBuffer = rCopy.m_pBuffer;
    m_Size    = rCopy.m_Size;
    
    rCopy.m_pBuffer = NULL;
    rCopy.m_Size = 0;
    
    return *this;
}

// -------------------------------------------------------------------------------------------------

template <typename TType>
CB_FORCEINLINE void CB_INLINE_ATTR CAutoBuffer<TType>::SetBuffer(TType*& _rpBuffer, uint32 _Size)
{
 	Release();
    m_pBuffer = _rpBuffer;
    m_Size = _Size;   
    
    _rpBuffer = NULL;
}

// -------------------------------------------------------------------------------------------------

template <typename TType>
CB_FORCEINLINE TType* CB_INLINE_ATTR CAutoBuffer<TType>::Retain()
{
	TType* pBuffer = m_pBuffer;
    m_pBuffer = NULL;
    m_Size = 0;
    
	return pBuffer;
}

// -------------------------------------------------------------------------------------------------

template <typename TType>
CB_FORCEINLINE void CB_INLINE_ATTR CAutoBuffer<TType>::Release()
{
    delete[] m_pBuffer;
    m_pBuffer = NULL;
    m_Size = 0;
}

#endif
#endif